<template>
	<view class="wrapForm">
		<view class="bgLine flex jst-between pL25 pR25 pT20 pB20"></view>

		<view class="wrapFormBody pL15 pR15 pT15 rzBox">
			<u-form :label-width="200" :error-type="['toast']" :label-style="{'font-size':'30rpx'}" class="xf-wrap-form"
				ref="formData" :rules="rulers" :model="formData">
				<u-form-item :required="true" label="真实姓名" :label-position="'top'" prop="realName">
					<view class="w100">
						<u-input  placeholder="请输入真实姓名" v-model="formData.realName" />

					</view>
				</u-form-item>
				<u-form-item :required="true" label="身份证号" :label-position="'top'" prop="idCard">
					<view class="w100 ">
						<u-input placeholder="请输入身份证号" v-model="formData.idCard" />
					</view>
				</u-form-item>
				<u-form-item :required="true" label="联系电话" :label-position="'top'" prop="userPhoneNo">
					<view class="w100 ">
						<u-input placeholder="请输入联系电话" v-model="formData.userPhoneNo" />
					</view>
				</u-form-item>
				<u-form-item :required="true" label="地址" :label-position="'top'" prop="address">
					<view class="w100 flex alg-center jst-between">
						<view class="w70"><u-input :disabled="true" placeholder="请选择地址" v-model="formData.address" />
						</view>
						<image @click="chooseLocation" class="imgW36" :src="resources.posIcon" mode=""></image>
					</view>
				</u-form-item>
				<u-form-item :required="true" label="详细地址" :label-position="'top'" prop="homeAddress">
					<view class="w100 ">
						<u-input placeholder="请输入详细地址" v-model="formData.homeAddress" />
					</view>
				</u-form-item>
				<u-form-item label="期望工作" prop="expectedPositionText" :required="true" :label-position="'top'">
					<view class="w100 ">
						<u-input type="select" placeholder="请选择期望职位" @click="openJobType" :input-align="'left'"
							v-model="formData.expectedPositionText"></u-input>

					</view>
				</u-form-item>
				<u-form-item :required="true" label="所属驿站" :label-position="'top'" prop="organizationName">
					<view class="w100 ">
						<u-input type="select" placeholder="请选择地址" v-model="formData.organizationName"
							@click="showPicker" />
					</view>
				</u-form-item>


			</u-form>
		</view>
		<view class="flex jst-center  bottomFixed pT15 pB15 bgf">
			<view class="pointer rightNowPay u-f font15 t-center" @click="saveMyInfo">
				保存
			</view>
		</view>
		<jobType ref="jobType" @getSelV="getSelV" :isMultie="true" :title="'请选择期望职位'"
			:defaultValue="formData.expectedPosition" :showLength="true" :checkLength="3"></jobType>
		<xfTreePicker :defalutValue="formData.organizationId" :selectParent="false" ref="treePicker" :multiple="false"
			@select-change="selectChange" title="所属驿站" :localdata="deptLis" valueKey="id" textKey="name"
			codeKey="orgCode" childrenKey="children"></xfTreePicker>
	</view>
</template>

<script>
	import {
		brokerUpdateUserFeedback,
		brokerUpdateUser
	} from "@/api/economicInterface/user.js"
	import {
		getOrgTree
	} from "@/api/common.js"
	import selAreaMinxs from "@/utils/selArea.js"
	import {
		chooseLocal
	} from "@/libs/map.js"
	import jobType from "@/components/job/jobType/index.vue"
	export default {
		mixins: [selAreaMinxs],
		components: {
			jobType
		},
		data() {
			return {
				current: 0,

				formData: {
					xfOddUserId:"",
					"realName": "",
					"idCard": "",
					 userPhoneNo: "",
					"organizationId": "",
					organizationName: "",
					"homeAddress": "",
					"provinceId": "",
					"provinceName": "",
					"cityId": "",
					"cityName": "",
					"areaId": "",
					"areaName": "",
					"townId": "",
					"townName": "",
					address: "",
					longitude: "",
					latitude: "",
				},
				deptLis: [],
				rulers: {
					realName: [{
						required: true,
						message: '请输入真实姓名',
						trigger: ['change', 'blur'],
					}],
					idCard: [{
						required: true,
						message: '请输入身份证号',
						trigger: ['change', 'blur'],
					}, {
						rule: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X|x)$/,
						msg: '请正确输入您的身份证号码15-18位'
					}],
					userPhoneNo: [{
						required: true,
						message: '联系电话不能为空',
						trigger: ['change', 'blur']
					}, {
						pattern: /^1[3456789]\d{9}$/,
						message: '手机号格式不正确',
						trigger: ['change', 'blur']
					}],
					address: [{
						required: true,
						message: '请选择地址',
						trigger: ['change', 'blur'],
					}],
					homeAddress: [{
						required: true,
						message: '请输入详细地址',
						trigger: ['change', 'blur'],
					}],
					expectedPositionText: [{
						required: true,
						message: '请选择期望职位',
						trigger: ['change', 'blur'],
					}],
					organizationName: [{
						required: true,
						message: '请选择所属服务站点',
						trigger: ['change', 'blur'],
					}]

				}
			}
		},
		onReady() {

			this.$refs.formData.setRules(this.rulers);
			this.getTreeOpt()
		},
		onLoad(e) {
			this.formData.xfOddUserId=e.id;
			this.getInfo(e.id)
		},
		methods: {
			getInfo(id) {
				brokerUpdateUserFeedback({
					id: id
				}).then(res => {
					
					this.formData.realName = res?.result.realName;
					this.formData.address = res?.result.provinceName + res?.result.cityName + res?.result.areaName
					this.formData.homeAddress = res?.result.homeAddress;
					this.formData.idCard = res?.result.idCard;
					this.formData.expectedPositionText = res?.result.expectedPositionText;
					this.formData.expectedPosition = res?.result.expectedPosition
					this.formData.userPhoneNo = res?.result.userPhoneNo;
					this.formData.longitude =res?.result.longitude;
					this.formData.latitude = res?.result.latitude;
					this.formData.provinceId = res?.result.provinceId;
					this.formData.cityId = res?.result.cityId;
					this.formData.areaId =res?.result.areaId;
					this.formData.provinceName = res?.result.provinceName;
					this.formData.cityName = res?.result.cityName;
					this.formData.areaName =res?.result.areaName;
					this.formData.organizationId = res?.result.organizationId;
					this.formData.organizationName =res?.result.organizationName;
				})
			},
			showPicker() {
				this.$refs.treePicker._show();
			},
			//监听选择（ids为数组）
			selectChange(ids, code, names) {
				if (this.current == 0) {
					this.formData.organizationName = names;
					this.formData.organizationId = ids;
				} else {
					this.formData.organizationName = names;
					this.formData.organizationId = ids;
				}


			},
			//打开全部职位选择框
			openJobType() {
				this.$refs.jobType.openPoup()
			},
			getSelV(e, v) {
				this.formData.expectedPosition = e;
				this.formData.expectedPositionText = v;

			},
			async chooseLocation() {
				let res = await chooseLocal();
				let r = res.address + res.name;
				let d = this.regionDiscern(r)
				this.formData.provinceId = d.data.province.code;
				this.formData.cityId = d.data.city.code;
				this.formData.areaId = d.data.area.code;
				this.formData.provinceName = d.data.province.name;
				this.formData.cityName = d.data.city.name;
				this.formData.areaName = d.data.area.name;
				this.formData.address = this.formData.provinceName + this.formData.cityName + this.formData.areaName
				this.formData.latitude = res.latitude;
				this.formData.longitude = res.longitude;
				this.formData.homeAddress = d.data.address;


			},
			getTreeOpt() {
				getOrgTree().then(res => {
					this.deptLis = res.result[0].children;
				})
			},
			saveMyInfo() {
				this.$refs.formData.validate(async valid => {
					if (valid) {
						let data = this.xf.deepClone(this.formData)
						delete data.address
						brokerUpdateUser(data).then(res=>{
							this.xf.onlineUtils.toast("修改成功!")
							setTimeout(()=>{
								uni.navigateBack()
							},2000)
						})
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	page {
		height: 100%;
		background-color: #fff;
	}

	.wrapFormBody {
		padding-bottom: 200rpx;

		.reasonBox {
			.u-input {
				border-radius: 20rpx !important;
			}
		}
	}
</style>
<style lang="scss" scoped>
	.wrapForm {
		.sfSelItem {

			background: #F8F8F8;
			border-radius: 20rpx;
			padding: 20rpx 30rpx;
			border: 2rpx solid transparent;
			color: #8d8d8d;

			&.active {
				border-radius: 20rpx;
				border: 2px solid #00A0C6;
				background: #EBFCFF;
				color: #00A0C6;
			}


		}

		.rzCardBox {

			height: 128rpx;
			background: #F8F8F8;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-top: 60rpx;

			&:last-child {
				margin-top: 30rpx;
			}

			.imgRzCard {
				width: 40rpx;
				height: 32rpx;
			}
		}

		height: 100%;
		padding-bottom: 100rpx;

		.wrapFormBody {
			margin-top: -30rpx;
			border-radius: 40rpx 40rpx 0 0;
			background: #fff;
		}

		.uni-forms-item {
			align-items: center !important;
		}

		.uni-input-placeholder {
			text-align: left !important;
			color: #BDBDBD !important;
		}
	}

	.bgLine {
		background-color: #EBFCFF;
		width: 100%;
		// height: 60rpx;
		padding: 30rpx 40rpx;

		.rzImg {
			width: 168rpx;
			height: 192rpx;
		}
	}


	.rightNowPay {
		width: 670rpx;
		height: 100rpx;
		line-height: 100rpx;
		background: #00A0C6;
		border-radius: 30rpx;

	}
</style>